package com.tbit.uqbike.service.business.impl;

import com.tbit.uqbike.object.pojo.ParkPointApply;
import com.tbit.uqbike.service.business.ParkPointApplyService;
import com.tbit.uqbike.webmanager.dao.core.ParkPointApplyDao;
import com.tbit.utils.DateTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("parkPointApplyService")
public class ParkPointApplyServiceImpl implements ParkPointApplyService {
    @Autowired
    private ParkPointApplyDao parkPointApplyDao;


    @Override
    public Integer queryCount(List<Integer> accountIdList, Integer state, Long startTime, Long endTime, String phone) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("accountIdList", accountIdList);
        params.put("state", state);
        params.put("phone", phone);
        if (startTime != null) {
            params.put("startTime", DateTimeUtil.DateTimeToStringYMD(new Date(startTime)) + " 00:00:00");
        }
        if (endTime != null) {
            params.put("endTime", DateTimeUtil.DateTimeToStringYMD(new Date(endTime)) + " 23:59:59");
        }

        return parkPointApplyDao.queryCount(params);
    }

    @Override
    public List<ParkPointApply> queryPage(List<Integer> accountIdList, Integer state, Long startTime, Long endTime,
                                          Integer rowCount, Integer pageNO, String sortName, String phone) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("accountIdList", accountIdList);
        params.put("state", state);
        params.put("phone", phone);
        if (startTime != null) {
            params.put("startTime", DateTimeUtil.DateTimeToStringYMD(new Date(startTime)) + " 00:00:00");
        }
        if (endTime != null) {
            params.put("endTime", DateTimeUtil.DateTimeToStringYMD(new Date(endTime)) + " 23:59:59");
        }
        params.put("start", (pageNO - 1) * rowCount);
        params.put("rowCount", rowCount);
        params.put("sortName", sortName);
        return parkPointApplyDao.queryPage(params);
    }

    @Override
    public void handleNearBy(ParkPointApply parkPointApply) {
        parkPointApply.setState(1);
        parkPointApply.setRemark("自动审核附近站点申请");
        parkPointApply.setHandleInfo("审核通过");
        parkPointApplyDao.handle(parkPointApply);
    }

    @Override
    public int queryCountIds(List<Integer> accountIds, int type, Date startTime, Date endTime) {
        return parkPointApplyDao.queryCountIds(accountIds, type, startTime, endTime);
    }

    @Override
    public void insert(ParkPointApply parkPointApply) {
        parkPointApplyDao.insert(parkPointApply);

    }

    @Override
    public ParkPointApply getByParkPointApplyId(Integer parkPointApplyId) {
        return parkPointApplyDao.getByParkPointApplyId(parkPointApplyId);
    }

    @Override
    public void handle(ParkPointApply parkPointApply) {
        parkPointApplyDao.handle(parkPointApply);
    }

    @Override
    public List<ParkPointApply> selectList(Integer userId, List<Integer> accountIdList, Date startTime, Date endTime) {
        return parkPointApplyDao.selectList(userId, accountIdList, startTime, endTime);
    }
}